package com.openthinks.joyniproject.utils.spring;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.openthinks.joyniproject.utils.Init;

/**
 * 注入
 * @author Administrator
 *
 */

public class ApplicationCtxInit implements ServletContextListener  {

	private static WebApplicationContext ctx;
	
	private static ApplicationContext servletCtx;
	
	private static ServletContext sc;
	
	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		
	}
	@Override
	public void contextInitialized(ServletContextEvent event) {
		
		sc = event.getServletContext();
		ctx = WebApplicationContextUtils.getWebApplicationContext(sc);
		Init.springInitFinish = true;
		Init.init();
	}
	
	public static WebApplicationContext getCtx() {
		return ctx;
	}
	public static ApplicationContext getServletCtx() {
		return servletCtx;
	}
	public static void setServletCtx(ApplicationContext servletCtx) {
		ApplicationCtxInit.servletCtx = servletCtx;
	}
	public static void setCtx(WebApplicationContext ctx) {
		ApplicationCtxInit.ctx = ctx;
	}
	public static ServletContext getSc() {
		return sc;
	}
	public static void setSc(ServletContext sc) {
		ApplicationCtxInit.sc = sc;
	}

}
